
package com.csun.cmny.provider.web.rpc;

import com.csun.cmny.base.dto.CacReturnDto;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.vo.CareTypeCountVo;
import com.csun.cmny.provider.service.CacOldmanFeignApi;
import com.csun.cmny.provider.service.CacOldmanMinorService;
import com.csun.cmny.provider.service.CacOldmanService;
import com.csun.cmny.util.PublicUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class CacOldmanFeignClient extends BaseController implements CacOldmanFeignApi {

    @Autowired
    private CacOldmanService cacOldmanService;
    @Autowired
    private CacOldmanMinorService cacOldmanMinorService;

    @Override
    @ApiOperation(httpMethod = "POST", value = "根据老人Id获取评估信息")
    public Wrapper getEstimateByOld(Integer oldmanId) {
        Map queryMap = new HashMap();
        queryMap.put("oldmanId",oldmanId);
        List<Map<String, Object>> mapList = cacOldmanService.showAll(queryMap);
        return WrapMapper.ok(mapList);
    }

    @Override
    @ApiOperation(httpMethod = "POST", value = "根据老人Id获取评估信息")
    public Wrapper<List<Map<String, Object>>> getCacOldmanInfo(@RequestParam("oldmanId")Integer oldmanId,
                                                               @RequestParam("cacId")Integer cacId,
                                                               @RequestParam("bigItemId")Integer bigItemId) {
        Map queryMap = new HashMap();
        queryMap.put("oldmanId",oldmanId);
        queryMap.put("cacId",cacId);
        queryMap.put("bigItemId",bigItemId);
        List<Map<String, Object>> mapList = cacOldmanService.getCacOldmanInfo(queryMap);
        return WrapMapper.ok(mapList);
    }

    @Override
    @ApiOperation(httpMethod = "POST", value = "根据老人Id删除评估及小项信息")
    public Integer deleteCacOldman(Integer oldmanId) {
        //删除老人评估信息同时删除小项关系
        Integer n = cacOldmanService.deleteByOldmanId(oldmanId);
        return n;
    }

    @Override
    @ApiOperation(httpMethod = "POST", value = "根据老人Id查询评估信息")
    public Wrapper<List<CacReturnDto>> selectCacOldMnr(Integer oldmanId) {
        return WrapMapper.ok(cacOldmanMinorService.selectByOldmanId(oldmanId) );
    }

    @Override
    @ApiOperation(httpMethod = "POST", value = "统计各个护理类型数量")
    public Wrapper<List<CareTypeCountVo>> queryOldmanNumGroupByCareType(@RequestParam(value = "oldmanIdList") List<Integer> oldmanIdList) {
        List<CareTypeCountVo> vos = cacOldmanService.queryOldmanNumGroupByCareType(oldmanIdList);
        return WrapMapper.ok(vos);
    }

    @Override
    public Wrapper<List<Integer>> queryNeedDailyEvaluateOldmanIdList(@RequestParam(value = "groupId") Long groupId) {
        List<Integer> oldmanIdList = cacOldmanService.queryNeedDailyEvaluateOldmanIdList(groupId);
        return WrapMapper.ok(oldmanIdList);
    }

    @Override
    public Wrapper<List<Map<String, Object>>> selectCacOldManAll() {
        List<Map<String, Object>> mapList = cacOldmanService.selectCacOldManAll();
        return WrapMapper.ok(mapList);
    }

    @Override
    public Wrapper<Integer> updateLevelCare(@RequestBody List<Map<String, Object>> updateDtos) {

        log.info("=====> chisj this is updateLevelCare.");

        Integer update=cacOldmanService.updateLevelCare(updateDtos);

        return WrapMapper.ok(update);
    }

    @Override
    public Wrapper<Integer> test(@RequestBody List<Map<String, Object>> updateDtos) {

        log.info("=====> chisj this is test.");

        return WrapMapper.ok(123);
    }
}

